<?php
namespace app\models;

use yii\db\ActiveRecord;
use Yii;

class wall extends ActiveRecord{
	public static function tableName(){
		return "{{%wall}}";
	}

	public function rules(){
		return[
		    ['content', 'required', 'message' => '提交的内容不能为空~'],
		    ['content', 'string', 'max' => 600],
		    ['sex', 'in', 'range' => [0,1], 'message' => '性别错误~'],
		    ['ip', 'required', 'message' => '用户IP不能为空'],
		];
	}

	public function add($data , $IP){
		if($this->load($data)){
			$this->content = $data['content'];
			$this->sex = $data['sex'];
			$this->ip = $IP;
			$result = $this->save();
			if($result){
				$error = 0;
				return $error;
			}else{
				$error = $this->getErrors();
				return $error;
			}
		}else{
			$error = 2;
			return $error;
		}
	}


}